# -*- coding: utf-8 -*-
# @File      :connect_mogo
# @Author    :liaogan
# @Datetime  :2023/2/21 12:19
import pymongo

#创建连接
client=pymongo.MongoClient("mongodb://admin:sq@192.168.73.131:27017")

#指定数据库
db=client['sq-waimai']

#指定集合
collection=db['categories']


#增加一条数据
collection.insert_one({"count":1111,"level":2,"name":"快餐便当2"})

# 增加多条数据
# mylist=[
#     {"count":10,"level":2,"name":"快餐便当4"},
#     {"count":10,"level":3,"name":"快餐便当5"}
# ]
# collection.insert_many(mylist)

# # 查询多个
# result=collection.find({"name":"快餐便当"})
# for one in result:
#     print(one)

# 查询单个
# result=collection.find_one({"name":"快餐便当"})
# print(result)

#修改操作
# collection.update_one({'count':10},{"$set":{"name":"快餐修改操作"}})

#修改多个操作
# collection.update_many({'count':10},{'$set':{'name':'周二'}})


#删除操作,只删除匹配到的一条数据
# collection.delete_one({"count":104})

#删除多条数据
# collection.delete_many({"count":10})